package com.example.blogdemo

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import androidx.core.app.ComponentActivity
import androidx.core.view.WindowCompat


val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)

val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)


val primaryMacaws = Color(0xffffffff)
val MacawsWhite = Color(0xffffffff)
val macawsTitleColor = Color(0xFF293040)
val macawsBodyColor = Color(0xFFA1A6B3)
val macawMainColor = Color(0xFFFF7024)
val dividerColor = Color(0xFFDFE1E6)

val macawsSliderThumbColor= Color(0xFFFFFFFF)
val macawsSliderActiveTrackColor= Color(0xFF285DC9)

/**
 * 加粗字体
 */
val fontBold = FontFamily.Default

/**
 * 正常字体
 */
val fontMedium = FontFamily.Default

val Typography = Typography(
    bodyLarge = TextStyle(
        fontFamily = fontMedium,
        fontWeight = FontWeight.Normal,
        fontSize = 14.sp,
        lineHeight = 24.sp,
        letterSpacing = 0.5.sp
    ),
    titleLarge = TextStyle(
        fontFamily = fontBold,
        fontWeight = FontWeight.Bold,
        fontSize = 20.sp,
        lineHeight = 28.sp,
        letterSpacing = 0.sp
    ),
    labelSmall = TextStyle(
        fontFamily = fontMedium,
        fontWeight = FontWeight.Medium,
        fontSize = 11.sp,
        lineHeight = 16.sp,
        letterSpacing = 0.5.sp
    )
)


private val DarkColorScheme = darkColorScheme(
    primary = Purple80,
    secondary = PurpleGrey80,
    tertiary = Pink80
)

private val LightColorScheme = lightColorScheme(
    primary = primaryMacaws,
    secondary = PurpleGrey40,
    tertiary = Pink40

    /* Other default colors to override
    background = Color(0xFFFFFBFE),
    surface = Color(0xFFFFFBFE),
    onPrimary = Color.White,
    onSecondary = Color.White,
    onTertiary = Color.White,
    onBackground = Color(0xFF1C1B1F),
    onSurface = Color(0xFF1C1B1F),
    */
)

@Composable
fun MacawsTheme(content: @Composable () -> Unit) {
    val dynamicColor = true
    val darkTheme = true
    val colorScheme = when {
        dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
            val context = LocalContext.current
            if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
        }

        darkTheme -> DarkColorScheme
        else -> LightColorScheme
    }
    val view = LocalView.current
    if (!view.isInEditMode) {
        SideEffect {
            val window = (view.context as Activity).window
            when (view.context) {
                is ComponentActivity -> {
                    (view.context as ComponentActivity).actionBar?.hide()
                }
            }
            window.statusBarColor = android.graphics.Color.WHITE
            window.decorView.setBackgroundColor(android.graphics.Color.WHITE)
            WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
        }
    }
    // 默认填充满。
    Column(modifier = Modifier.fillMaxSize()) {

    }
    MaterialTheme(
        colorScheme = LightColorScheme,
        typography = Typography,
        content = content,
    )
}


val title18Bold = TextStyle(
    fontFamily = fontBold,
    fontWeight = FontWeight.Bold,
    fontSize = 18.sp,
    color = macawsTitleColor,
    letterSpacing = 0.sp
)
val title18Medium = TextStyle(
    fontFamily = fontMedium,
    fontWeight = FontWeight.Medium,
    fontSize = 18.sp,
    color = macawsTitleColor,
    letterSpacing = 0.sp,
    lineHeight = 24.sp
)
val body14Medium = TextStyle(
    fontFamily = fontMedium,
    fontWeight = FontWeight.Medium,
    fontSize = 14.sp,
    color = macawsBodyColor,
    letterSpacing = 0.sp,
    lineHeight = 19.sp
)
val title18Normal = TextStyle(
    fontFamily = fontMedium,
    fontWeight = FontWeight.Normal,
    fontSize = 18.sp,
    color = macawsTitleColor,
    letterSpacing = 0.sp
)
val text16WBold = TextStyle(
    fontFamily = fontBold,
    fontWeight = FontWeight.Bold,
    fontSize = 16.sp,
    color = primaryMacaws,
    letterSpacing = 0.sp
)
val text16TitleMedium = TextStyle(
    fontFamily = fontMedium,
    fontWeight = FontWeight.Medium,
    fontSize = 16.sp,
    color = macawsTitleColor,
    letterSpacing = 0.sp
)
val text14BodyMedium = TextStyle(
    fontFamily = fontMedium,
    fontWeight = FontWeight.Medium,
    fontSize = 14.sp,
    color = macawsBodyColor,
    letterSpacing = 0.sp
)
